from django.db import models
from django.contrib.auth import get_user_model
from apps.courses.models import Course
from apps.users.models import BaseModel

UserEntity = get_user_model()


# Create your models here.
# 实体{ 用户提问  消息  收藏   评论 }
class UserAsk(BaseModel):
    name = models.CharField(verbose_name="名称", max_length=48)
    mobile = models.CharField(verbose_name="手机", max_length=11)
    course_name = models.CharField(verbose_name="课程名", max_length=48)

    class Meta:
        verbose_name = "用户咨询"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.course_name


# 课程评论
class CourseComments(BaseModel):
    user = models.ForeignKey(UserEntity, verbose_name="用户", on_delete=models.CASCADE)
    course = models.ForeignKey(Course, verbose_name="课程", on_delete=models.CASCADE)
    comments = models.CharField(verbose_name="评论", max_length=128)

    class Meta:
        verbose_name = "课程评论"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.course.name


USER_FAVORITE_TYPE = (
    (1, "课程"),
    (2, "机构"),
    (3, "讲师")
)


# 用户收藏
class UserFavorite(BaseModel):
    user = models.ForeignKey(UserEntity, verbose_name="用户", on_delete=models.CASCADE)
    fav_id = models.IntegerField(verbose_name="收藏id")
    type = models.IntegerField(verbose_name="收藏类型", choices=USER_FAVORITE_TYPE, default=1)

    class Meta:
        verbose_name = "用户收藏"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.fav_id


# 用户消息
class UserMessage(BaseModel):
    user = models.ForeignKey(UserEntity, verbose_name="用户", on_delete=models.CASCADE)
    content = models.CharField(verbose_name="消息内容", max_length=300)
    has_read = models.BooleanField(verbose_name="是否已读", default=False)

    class Meta:
        verbose_name = "用户消息"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.content


# 用户课程关系
class RelUserCourse(BaseModel):
    user = models.ForeignKey(UserEntity, verbose_name="用户", on_delete=models.CASCADE)
    course = models.ForeignKey(Course, verbose_name="课程", on_delete=models.CASCADE)

    class Meta:
        verbose_name = "用户课程关系"
        verbose_name_plural = verbose_name

    def __str__(self):
        return "学习了：" + self.course.name
